package com.sevenmall.productservice.controller;


import com.sevenmall.productservice.pojo.Brand;
import com.sevenmall.productservice.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * <p>
 * 品牌商表 前端控制器
 * </p>
 *
 * @author Yesi
 * @since 2020-08-24
 */
@RestController
@RequestMapping("/brand")
public class BrandController {


    @Autowired
    BrandService brandService;

    @GetMapping("selectById/{id}")
    public Brand selectBrand(@PathVariable("id") Integer id){
        Brand brand = brandService.selectById(id);
        System.out.println(brand);
        return brand;
    }

    @GetMapping("insertBrand")
    public int insertBrand(Brand brand){
        LocalDateTime nowtime = LocalDateTime.now();
        Brand brand1 = new Brand("wangwu", "testinsert", "test3", "test3", 5, nowtime, nowtime, false);
        int feedback = brandService.insert(brand1);
        return feedback;
    }

    @GetMapping("deleteById/{id}")
    public int deleteById(@PathVariable("id")Integer id){
        int feedback = brandService.deleteById(id);
        return feedback;
    }

    @GetMapping("updateBrand")
    public int updateBrand(Brand brand){
        LocalDateTime nowtime = LocalDateTime.now();
        Brand brand1 = new Brand("wangsi", "testinsert", "test3", "test3", 5, nowtime, nowtime, false);
        brand1.setId(4);
        int feedback = brandService.update(brand1);
        return feedback;
    }

}
